﻿@using OBUCare.Core.Models
@using OBUCare.Web.Models
@using OBUCare.Web.Infrastructure
@{
    ViewBag.Title = "标签交接单管理"; //页面标题

    //string moduleID = Request["moduleID"] == null ? "" : Request["moduleID"].ToString();
    var menuName = PageData["moduleID"] == null ? UIUtility.getMenuName(Request.Url.LocalPath) : PageData["moduleID"];

    var operatorInfo = UIUtility.GetCurrentUser();

    ViewData["menuName"] = menuName;

    string AgentNoInfo = UIUtility.getAgentByModule(operatorInfo, menuName.ToString());

}
<link href="../../Content/tableCss.css" rel="stylesheet" type="text/css" />
<table width="100%">
    <tr>
        <td style="width: 100%; text-align: center">
            <span style="font-weight: bold; font-size: 16px">@ViewBag.Title</span>
        </td>
    </tr>
    <tr>
        <td>
            &nbsp;
        </td>
    </tr>
    <tr>
        <td style="width: 100%; text-align: center">
            @Html.Partial("_Search")
        </td>
    </tr>
    <tr>
        <td style="width: 100%; text-align: center">
            @(Html.Telerik().Grid<View_TRANSFER_BILL_Info>()
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.ID))
        .Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn))
                    //.Resizable(resizing => resizing.Columns(true))
        .DataBinding(dataBinding => dataBinding
            .Ajax()
            .Select("ListTransferBillSqlItems", "Transfer", new { sql = ViewBag.Sql })
            .Delete("Delete", "Transfer")
                    )
        .Columns(columns =>
        {
            columns.Bound(o => o.ID)
                .ClientTemplate("<input name='checkedRecords' type='checkbox' value='<#= ID #>' title='选中当前行'/> <#= ++index #>")
                .HeaderTemplate
                (
                    @<text>
            <input type="checkbox" title="全选" id="checkAllRecords" />
            </text>
                ).Width("5%");
            columns.Bound(o => o.TRANSFER_DATE).Format("{0:yyyy-MM-dd}").Width("8%");
            columns.Bound(o => o.TRANSFER_BILL_NO).ClientTemplate("<a href='/Transfer/ConfirmReceivedPreview/<#= ID #>?agentNo=" + AgentNoInfo + "'  target='_blank'><#= TRANSFER_BILL_NO #></a>").Width("10%");
            columns.Bound(o => o.STATUS_title).Width("9%");
            columns.Bound(o => o.TRANSFER_FROM_NAME).Title("交接来源").Width("7%");
            columns.Bound(o => o.TRANSFER_TO_NAME).Title("交接目的地").Width("8%");
            columns.Bound(o => o.Deliver_OPERATOR).Width("8%");
            //columns.Bound(o => o.SEND_PEOPLE).Width("8%");
            // columns.Bound(o => o.RECEIVE_OPERATOR).Width("8%");
            columns.Bound(o => o.TRANSFER_TYPE_Title).Width("8%");

            columns.Bound(o => o.ConfirmCommandTitle).ClientTemplate("<a abc='abc' name='<#= ConfirmCommandTitle #>' class='t-button' href='/Transfer/ConfirmReceivedNew/<#= ID #>' onclick='return confirmReceive();' style='display:<#= ConfirmVisable#>' ><#= ConfirmCommandTitle #></a>").Width("8%");
            columns.Bound(o => o.ID)
            .ClientTemplate("<input type='button' value='作废' name='deleteData' id='<#= ID #>' style='display:<#= deleteShow#>' onclick='deleteData(id)' />").Title("作废").Width("10%");
            //columns.Bound(o => o.ID).ClientTemplate("<a href='/Transfer/ConfirmReceivedPreview/<#= ID #>?agentNo=" + AgentNoInfo + "'  target='_blank'>详情</a>").Title("详情").Width("10%");
        }).TableHtmlAttributes(new { style = "width:180%" })
        .Editable(editing => editing.Mode(GridEditMode.PopUp))
        .ClientEvents(events =>
        {
            events.OnError("onError");
            events.OnDataBinding("onDataBinding");
            events.OnDataBound("onDataBound");
        })
        .Pageable(paging =>
        {
            paging.Style(CommonStyleForUI.Grid_PageStyle)
            .Position(CommonStyleForUI.Grid_PagePosition)
            .PageTo(CommonStyleForUI.Grid_CurrentPage)
            .PageSize(CommonStyleForUI.Grid_PageSize);
        })
        .Scrollable(scroll => scroll.Height(CommonStyleForUI.Grid_Height))
                    //.Selectable()
)
        </td>
    </tr>
</table>
@{  Html.Telerik().Window()
        .Name("Window")
        .Title("确定作废？")
        .Content(@<text>
    <form id="delForm">
    <div>
        <p>
            <label for="txtRemark">
                备注 <span style="color: red">*</span></label>
            <input type="hidden" id="HidbillID" style="width: 0px;" />
        </p>
        <p>
            <div>
                <textarea id="txtRemark" class="{required:true,messages:{required:'请输入内容'}}" style="width: 370px;
                    height: 100px;"></textarea>
            </div>
            <div>
                <span id="valRemark" style="color: red">请输入备注</span>
            </div>
        </p>
        <div style="float: right">
            <button type="button" id="btnSumitDeleteForm" class="t-button t-state-default">
                提交</button>
        </div>
    </div>
    </form>
    </text>)
        .Width(420)
        .Height(260)
        .Draggable(true)
        .Modal(true)
        .Visible(false)
        .Render();
}
<script type="text/javascript">

    $().ready(
        function () {
            //为全选框注册事件
            $('#checkAllRecords').click(function () {
                $("#Grid tbody input:checkbox").attr("checked", this.checked);
            });
            $("#Grid tbody tr th").attr("style", "text-align:center");

            $("#btnSumitDeleteForm").click(function () {
                confirmDelete();
            });
        }

        );

    var index = 0;

    function confirmReceive(e) {
        var isReceive = confirm("确认接收吗？");
        if (!isReceive) {
            return false;
        }
        index = 0;
    }


    function onDataBinding(e) {
        var grid = $('#Grid').data('tGrid')
        index = (grid.currentPage - 1) * grid.pageSize;
        e.data = {
            // the key ("category") specifies the variable name of the action method which will contain the specified value
            searchSql: $('#searchSql').val(),
            AgentNo: $('#AgentNo').val()
        };
    }

    function OnCommand(e) {
        return onDataBinding(e);
    }
    function onError(e) {
        //debugger;
        e.preventDefault();
        /*if (e.XMLHttpRequest.status == "505")
        alert("系统字段不允许删除");
        else if (e.XMLHttpRequest.status == "506")
        alert("系统表不允许删除");
        else*/
        alert(e.XMLHttpRequest.getResponseHeader("message"));
    }

    function onDataBound() {
        var items = $("a[abc=abc]");
        for (var i = 0; i < items.length; i++) {
            var strContent = $(items[i]).attr("name");
            if (strContent.StringIsNullOrEmpty()) {
                $(items[i]).attr("style", "display:none");
            }
        }
        replaceDeleteConfirmation(this, "Grid");
    }
    function deleteData(value) {
        $("#HidbillID").val(value);
        $("#valRemark").hide();
        $('#Window').data('tWindow').center().open();
    }

    function confirmDelete() {
        var id = $("#HidbillID").val();
        var agentNo = $('#AgentNo').val();
        var txtRemark = $("#txtRemark").val();

        if (!txtRemark.StringIsNullOrEmpty()) {
            var jdata = { ID: id, agentNO: agentNo, Remark: txtRemark };
            $.post("/Transfer/deleteTranfer", jdata,
                        function (data) {
                            if (data.Success == true) {
                                var grid = $('#Grid').data('tGrid');
                                //                                alert(grid);
                                grid.rebind();
                                //                                alert(data.ErrorMsg);
                                alert("作废成功");
                                var win = $('#Window').data('tWindow');
                                win.close();
                            }
                            else {
                                alert("作废失败：" + data.ErrorMsg);
                            }
                        });
        }
        else {
            $("#valRemark").show();
        }
    }

    function replaceDeleteConfirmation(item, itemType) {
        //debugger;
        var grid = $(item).data('tGrid');
        $(item).find('.t-grid-delete').click(function () {
            //grid.localization.deleteConfirmation = "你确定要删除此条记录： " + itemType + "?";
            var agentNo = $('#AgentNo').val();
            if (agentNo.length != 0) {
                alert("您没有权限作废此交接单！"); return false;
            }
            grid.localization.deleteConfirmation = "你确定要作废此交接单? ";

        });
    }
</script>
